//
//  feedbackController.m
//  美物说
//
//  Created by J on 15/8/28.
//  Copyright (c) 2015年 JZJ. All rights reserved.
//

#import "feedbackController.h"

@interface feedbackController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate>
@property(nonatomic,strong)UITableView* tableView;

@end

@implementation feedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createTableView];
    self.navigationItem.title=@"意见反馈";
}


- (void)createTableView
{
    
    
    //左边导航栏图标d
    
    
    UIBarButtonItem* rightBarButton=[[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(rightPush:)];
    
    
    self.navigationItem.rightBarButtonItem=rightBarButton;

    
    
    
    _tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [self.view addSubview:_tableView];
    
    
    
    
}



#pragma mark --UITableViewDataSource


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return 1;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"ID"];
    
    if (!cell) {
        
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
    }
    
    
    UITextView* view=[[UITextView alloc]init];
    view.delegate=self;
    
    view.textColor=[UIColor lightGrayColor];

    view.backgroundColor=[UIColor whiteColor];

    
    if (indexPath.section==0) {
        
        
        view.frame=CGRectMake(0, 0, self.view.frame.size.width, 50);
        
        view.text=@"小致菌很需要你的意见和建议~";
        view.tag=1000;


        [cell.contentView addSubview:view];
        return cell;

        

    }
    
    
    
    
        view.frame=CGRectMake(0, 0, self.view.frame.size.width, 40);
    view.text=@"电话/邮箱/QQ";
    view.textColor=[UIColor lightGrayColor];

        [cell.contentView addSubview:view];
    view.tag=2000;


    
    
    return cell;
    
    
    
}


- (float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section) {
        return 44;
    }else{
     
        
        return 1;
    }
    

    return 1;
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{


    
    
    switch (section) {
        case 0:
            
            
            return @"反馈内容";
            break;
            
        case 1:
            
            
            return @"联系方式";

            break;
    }
    
    return 0;



}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.section) {
        case 0:
            
            return 50;
            
            
            break;
            
        case 1:
            
            return 44;
            
            
            break;
    }

    return 0;

}



- (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{




    switch (section) {
               case 1:


            return @"加入极致漫画说QQ群,回复更佳及时哦~";

            break;
    }

    return 0;



}





- (void)textViewDidBeginEditing:(UITextView *)textView {
    if (textView.text !=nil) {
        textView.text = @"";
    }
}


//3.在结束编辑的代理方法中进行如下操作
- (void)textViewDidEndEditing:(UITextView *)textView {
    if (textView.text.length<1) {
        textView.text = @"想说的话";
    }
    
    [textView endEditing:YES];
    

//    UITextView* view1=[self.view viewWithTag:1000];
    
    
    
    
 
    [textView resignFirstResponder];

    
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    CGFloat offset = self.view.frame.size.height - (216 + 100);
    if (offset<=textView.frame.origin.y + textView.frame.size.height) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect frame = self.view.frame;
            frame.origin.y = frame.origin.y - (textView.frame.origin.y + textView.frame.size.height - offset);
            self.view.frame = frame;
        }];
    }
    return YES;
}

- (void)rightPush:(UIBarButtonItem*)sender {
   
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
    
    
}


@end
